<?php
include '../login/db_connect.php';
include '../login/functions.php';
sec_session_start ();

$email = $_SESSION ['email'];
$id_utente = $_SESSION ['user_id'];
$username = $_SESSION['username'];

$_SESSION ['user_id'] = $id_utente;
$_SESSION ['email'] = $email;
$_SESSION['username'] = $username;

if (isset ( $_COOKIE ['login_string'] )) {
	$login_string = $_COOKIE ['login_string'];
	$username = $_COOKIE ['username'];
	$user_id = $_COOKIE ['user_id'];
	
	$_SESSION ['user_id'] = $user_id;
	$_SESSION ['login_string'] = $login_string;
	$_SESSION ['username'] = $username;
}

?>
<div class="container">

	


	<div class="row">
		<div class="col-sm-7">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">Ricevuti</h3>
				</div>
				<div class="panel-body">
					<table class="table table-condensed table-striped"info'>
						<tr>
							<th align=center>MITTENTE
							
							<th align=center>OGGETTO
							
							<th align=center>DATA e ORA
							
							<td>Opzioni</td>
						</tr>
				
				
						<?php
						$query = "SELECT * FROM message";
						if ($result = $mysqli->query ( $query )) {
							/* fetch associative array */
							$count = 0;
							while ( $row = $result->fetch_assoc () ) {
								if ($row ['receiver'] == 19) {
									$count = $count + 1;
									
									echo "<tr>";
									echo "<td>", $row ['sender'];
									echo "<td>", $row ['subject'];
									echo "<td>", $row ['send_date'];
									$message = $row ['content'];
								
									echo "<td>","<button type=\"button\" class=\"btn btn-default\" data-container=\"body\" data-toggle=\"popover\" title=\"Popover title\" data-content=\"$message\"><span class=\"glyphicon glyphicon-eye-open\"></span></button>";
									
									
									echo "</tr>";
								}
							}
							
							/* free result set */
							// $result->free ();
						}
						?>
						</table>
				</div>
			</div>

			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">Inviati</h3>
				</div>
				<div class="panel-body">
					<table class="table table-condensed table-striped"info'>
						<tr>
							<th align=center>MITTENTE
							
							<th align=center>OGGETTO
							
							<th align=center>DATA e ORA
							
							<td>Opzioni</td>
						</tr>
				
				
						<?php
						$query = "SELECT * FROM message";
						if ($result = $mysqli->query ( $query )) {
							/* fetch associative array */
							$count = 0;
							while ( $row = $result->fetch_assoc () ) {
								if ($row ['sender'] == 19) {
									$count = $count + 1;
									
									echo "<tr>";
									echo "<td>", $row ['sender'];
									echo "<td>", $row ['subject'];
									echo "<td>", $row ['send_date'];
									echo "<td>", "<button class=\"btn btn-link\" data-toggle=\"modal\" data-target=\"#myModal\"><span class=\"glyphicon glyphicon-eye-open\"></span></button>";
									echo "<!-- Modal -->
<div class=\"modal fade\" id=\"myModal\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\">
  <div class=\"modal-dialog\">
    <div class=\"modal-content\">
      <div class=\"modal-header\">
        <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">&times;</button>
        <h4 class=\"modal-title\" id=\"myModalLabel\">Modal title</h4>
      </div>
      <div class=\"modal-body\">
        ", $row ['content'], "
      </div>
      <div class=\"modal-footer\">
        <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\" onclick= '<!-- QUI VA LA FUNZIONE CHE CAMBIA LO STATO --!>' >Close</button>
      </div>
    </div>
  </div>
</div>";
									echo "</tr>";
								}
							}
							
							/* free result set */
							// $result->free ();
						}
						?>
						</table>
				</div>
			</div>
		</div>

		<div class="col-sm-5">
			<div class="panel panel-success">
				<div class="panel-heading">
					<h3 class="panel-title">New Message</h3>
				</div>
				<div class="panel-body">
					<!-- FORM PER CREARE MESSAGGIO -->
					<form title="form_new_message" name=newmessform
						action="message_process.php" method=POST id="newmessage">

						<div class="form-group">
							<table>
								<tr>
									<td><label for="ricerca_vendor">Seleziona un fornitore</label> <input
						class="form-control dropdown-toggle" data-toggle="dropdown"
						placeholder="Digita un appellativo">
									
									<td><label>Lista destinatari</label><select
										class="form-control">
											<option>1</option>
											<option>2</option>
											<option>3</option>
											<option>4</option>
											<option>5</option>
									</select>
							
							</table>



						</div>

						<div class="form-group">
							<label for="Oggetto">Oggetto</label> <input type=text
								name=oggetto class=form-control required placeholder="Oggetto">
						</div>

						<div class="form-group">
							<label for="Messaggio">Messaggio</label>
							<textarea rows="8" name=messaggio class=form-control required
								placeholder="messaggio"></textarea>
						</div>

						<button class="btn btn-lg btn-success btn-block" type="submit">Invia</button>
					</form>

				</div>
			</div>
		</div>


	</div>
</div>

